package customermanagesystem.demo.Config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Autowired
    LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**")
////                .excludePathPatterns("/login","/index2","/customerManager","/","/css/*","/images/*","/js/*");//不会被拦截的目录
//                .excludePathPatterns("/login","/index2","/customerManager","/","/css/*","/images/*","/js/*");//不会被拦截的目录
//        /*代表拦截一级目录，/test/a不会被拦截; /**代表拦截所有请求 /只拦截根目录，即localhost:8080
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(loginInterceptor);
        interceptorRegistration.addPathPatterns("/**");
        interceptorRegistration.excludePathPatterns("/login.html","/customerManager.html","/index.html","/productManager.html","/js/*","/css/*","/images/*.jpg","/images/*.png","/","/*");
        interceptorRegistration.excludePathPatterns("/css/dmaku.css");
        interceptorRegistration.excludePathPatterns("/css/index.css");
        interceptorRegistration.excludePathPatterns("/css/style.css");
        interceptorRegistration.excludePathPatterns("/css/external/*.css");
        interceptorRegistration.excludePathPatterns("/js/external/*.js");
        interceptorRegistration.excludePathPatterns("/upload");
        interceptorRegistration.excludePathPatterns("/resources/static/images/*.jpg");
        interceptorRegistration.excludePathPatterns("/resources/static/images/*.png");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        配置静态资源映射，访问images就会找绝对路径
        registry.addResourceHandler("/static/images/**").addResourceLocations("file:D:\\桌面\\MVC框架\\项目\\src\\main\\resources\\static\\images\\"); /*绝对路径*/
    }
}
